package com.itsu.mongodb.service.impl;

import com.itsu.interfaces.entity.Users;
import com.itsu.interfaces.service.UsersService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public void addUsers(Users users) {
        mongoTemplate.insert(users);
    }

    @Override
    public List<Users> findUsersList(Long userId) {
        return mongoTemplate.find(Query.query(Criteria.where("userId").is(userId)), Users.class);
    }
}
